package com.niodata.dp.task.dao;

import com.niodata.dp.task.entity.PluginDocument;
import org.apache.ibatis.annotations.Delete;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;

@Mapper
public interface PluginDocumentMapper {

  @Insert("insert into PLUGIN_DOC(PKG_ID,PKG_VERSION,PKG_NAME,PKG_DOC)"
      + "VALUES(#{d.pkgId},#{d.version},#{d.name},#{d.document})")
  public void saveDocument(@Param("d") PluginDocument document);

  @Delete("delete from PLUGIN_DOC where PKG_NAME=#{name} and PKG_VERSION=#{version}")
  public void deleteDocument(@Param("name") String name,
      @Param("version") String version);

  @Update("update PLUGIN_DOC set PKG_DOC=#{d.document} where PKG_NAME=#{d.name} "
      + "and PKG_VERSION=#{d.version}")
  public void updateDocument(@Param("d") PluginDocument document);

  @Select("select PKG_ID as pkgId,PKG_NAME as name,PKG_VERSION as version,"
      + "PKG_DOC as document from PLUGIN_DOC where PKG_NAME=#{name} "
      + "and PKG_VERSION=#{version}")
  public PluginDocument getDocument(@Param("name") String name,
      @Param("version") String version);
}
